repo: Add OSTREE_REPO_TEST_ERROR=pre-commit env var
authorColin Walters <walters@verbum.org>
Tue, 19 Apr 2016 16:11:01 +0000 (12:11 -0400)
committerColin Walters (automation) <walters+githubbot@verbum.org>
Mon, 2 May 2016 18:44:44 +0000 (18:44 +0000)
Setting this causes commit to error out.  There are other ways we
could do this in a more sophisticated fashion, such as via SystemTap
etc.  But this has low-tech applicablity, works as non-root.

The reason I'm adding this is so that we can add test cases for
cleanup of the `tmp/staging-` directory.

Closes: #170
Approved by: jlebon

src/libostree/ostree-repo-commit.c
src/libostree/ostree-repo-private.h
src/libostree/ostree-repo.c
tests/basic-test.sh

index cd365da9738991632ac5deae25a03b017e5d1b46..8e00646c83f0f1845ec232ea645dcefcc1897113 100644 (file)
@@ -1442,6 +1442,13 @@ ostree_repo_commit_transaction (OstreeRepo                  *self,
 
   g_return_val_if_fail (self->in_transaction == TRUE, FALSE);
 
+  if ((self->test_error_flags & OSTREE_REPO_TEST_ERROR_PRE_COMMIT) > 0)
+    {
+      g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
+                           "OSTREE_REPO_TEST_ERROR_PRE_COMMIT specified");
+      goto out;
+    }
+
   if (syncfs (self->tmp_dir_fd) < 0)
     {
       glnx_set_error_from_errno (error);
index 54127be0316f2073edf683c4ad7027d0a5ac694b..70600f4e4d87d31a9fb4de6c9375afc5c62cde24 100644 (file)
@@ -36,6 +36,10 @@ G_BEGIN_DECLS
 #define _OSTREE_SUMMARY_CACHE_DIR "summaries"
 #define _OSTREE_CACHE_DIR "cache"
 
+typedef enum {
+  OSTREE_REPO_TEST_ERROR_PRE_COMMIT = (1 << 0)
+} OstreeRepoTestErrorFlags;
+
 /**
  * OstreeRepo:
  *
@@ -86,6 +90,8 @@ struct OstreeRepo {
   uid_t target_owner_uid;
   gid_t target_owner_gid;
 
+  guint test_error_flags; /* OstreeRepoTestErrorFlags */
+
   GKeyFile *config;
   GHashTable *remotes;
   GMutex remotes_lock;
index 420e2afbabb4cca7338c945a51d89e6f35b9ba5c..d44aeabeefd9170591f5a8e87f16597e8d9bef62 100644 (file)
@@ -798,6 +798,9 @@ ostree_repo_init (OstreeRepo *self)
 {
   static gsize gpgme_initialized;
   GLnxLockFile empty_lockfile = GLNX_LOCK_FILE_INIT;
+  const GDebugKey test_error_keys[] = {
+    { "pre-commit", OSTREE_REPO_TEST_ERROR_PRE_COMMIT },
+  };
 
   if (g_once_init_enter (&gpgme_initialized))
     {
@@ -806,6 +809,9 @@ ostree_repo_init (OstreeRepo *self)
       g_once_init_leave (&gpgme_initialized, 1);
     }
 
+  self->test_error_flags = g_parse_debug_string (g_getenv ("OSTREE_REPO_TEST_ERROR"),
+                                                 test_error_keys, G_N_ELEMENTS (test_error_keys));
+
   g_mutex_init (&self->cache_lock);
   g_mutex_init (&self->txn_stats_lock);
 
index 5519764a70ee10586a7926b75a822979e8c1b5ca..2edb15d20b02b118b36cfc8317e29e41e764ed2c 100755 (executable)
@@ -19,7 +19,7 @@
 
 set -euo pipefail
 
-echo "1..53"
+echo "1..54"
 
 $OSTREE checkout test2 checkout-test2
 echo "ok checkout"
@@ -397,6 +397,15 @@ assert_file_has_content test2-checkout/baz/cow moo
 assert_has_dir repo2/uncompressed-objects-cache
 echo "ok disable cache checkout"
 
+cd ${test_tmpdir}
+rm checkout-test2 -rf
+$OSTREE checkout test2 checkout-test2
+if env OSTREE_REPO_TEST_ERROR=pre-commit $OSTREE commit -b test2 -s '' $test_tmpdir/checkout-test2 2>err.txt; then
+    assert_not_reached "Should have hit OSTREE_REPO_TEST_ERROR_PRE_COMMIT"
+fi
+assert_file_has_content err.txt OSTREE_REPO_TEST_ERROR_PRE_COMMIT
+echo "ok test error pre commit"
+
 # Whiteouts
 cd ${test_tmpdir}
 mkdir -p overlay/baz/